package com.bankfourfactor;

import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.seek.cache.CacheUtil;
import com.seek.common.handler.SpringContextHolder;
import com.seek.model.dto.ResultInfo;
import com.seek.model.entity.TBaseBanktype;
import com.seek.service.BankFourFactorService;
import com.seek.util.BankNameUtil;
import com.seek.util.CommonUtil;
import com.seek.util.DateUtil;

import sun.applet.Main;

public class BankFourFactor {
	 private  static Logger logger = LoggerFactory.getLogger(BankFourFactor.class); 
	 private BankFourFactorService bankFourFactorService = null;
	public  ResultInfo submitYouDunFactor(BankCarFactorEntity b) throws Exception{
		ResultInfo result = new ResultInfo();
		ResParam param = new ResParam();
		/**验证是否成功1：审核通过，2，审核不通过**/
		int processCode = 0;
			Map<String,Object> repMap = new HashMap<String,Object>();
			Map<String,String> data = new HashMap<String,String>();
			data.put("id_name",b.getIdName());
			data.put("bank_card_no",b.getCardNo());
			data.put("id_no",b.getIdNo());
			data.put("mobile",b.getPhone());
			data.put("req_type",BankCarFactoryConstant.YOUDUN_REQ_TYPE);
			bankFourFactorService = (BankFourFactorService)SpringContextHolder.getBean("udBankFourFactorService"); 
			 repMap = bankFourFactorService.process(data, b);
			 processCode = CommonUtil.getIntValue(repMap.get("processCode"));
			 logger.info(processCode+"-========================");
			if(processCode==0){
			//走楠云
				bankFourFactorService = (BankFourFactorService)SpringContextHolder.getBean("nyBankFourFactorService");
				repMap = bankFourFactorService.process(data,b);
				processCode = CommonUtil.getIntValue(repMap.get("processCode"));
				logger.info(processCode+"BankFourFactor.processCode{}");
				if(processCode==0||processCode==2||processCode==3){
					result.setStatus(1);
					result.setMessage("操作失败，请重试");
				}else{
					result.setStatus(0);
					result.setMessage("操作成功");
				}
			}else if(processCode==1){
				result.setStatus(0);
				result.setMessage("操作成功");
			}else{
				result.setStatus(2);
				result.setMessage("操作失败，请重试");
			}
				
		param = repMap.containsKey("param")?(ResParam)repMap.get("param"):param;
		
		
		if(null!=param){
		TBaseBanktype baseBankType = CacheUtil.getTBaseBanktype(BankNameUtil.getBankName(param.getBankName()));
			if(null!=baseBankType){
				param.setLogoUrl(baseBankType.getTypeLogo());
			}
		}
		param.setSubmitTime(DateUtil.dateFormat(new Date(),DateUtil.DATE_FORMAT_YMD));
//		param.setCardNo(b.getCardNo());
		result.setBody(param);
		return result;
	}
	
	
public static void main(String[] args) throws ParseException {
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	String time = sdf.format(new Date());
	
	System.out.println();
}	
	
	
}
